<?php
if(!defined('IN_KKFRAME')) exit();
if(!$_GET['skip']) include template('header');

if($_K['uid'] && !$_GET['skip']){
	echo <<<EOF
<div class="page-headers"><h1>最新帖子</h1></div>
<div class="thread-list">
EOF;
}
if($page > 1){
	echo '<a href="?page='.($page - 1).'" id="prev_page_link" onclick="load_prev_page();return false;" class="page_loader">点击加载上一页</a>';
	echo '<div class="page_loader center" id="prev_page_waiter">加载中...</div><div id="prev_page_loader"></div>';
}
echo '<div id="posts">';
foreach($threadlist as $thread){
	$style = $style ? 0 : 1;
	echo '<a href="thread.php?id='.$thread['tid'].'">';
	echo '<div class="thread style_'.$style.' clearfix">';
	echo '<h5>'.$thread['subject'].'</h5></div></a>';
}
echo '</div>';
if($max_page > $page){
	echo '<div id="next_page_loader"></div><div class="page_loader center" id="next_page_waiter">加载中...</div>';
	echo '<a href="?page='.($page + 1).'" id="next_page_link" class="page_loader text-right" onclick="load_next_page();return false;">点击加载下一页</a>';
}
echo <<<EOF
</div>
<br>
<div class="page-headers"><h1>发表新帖</h1></div>
<form method="post" action="new.php">
<p><select style="width: 100%" name="fid">
EOF;
	foreach($_K['config']['forums'] as $forumid=>$forumname){
		echo "<option value=\"{$forumid}\"{$selected}>{$forumname}</option>";
	}
	echo <<<EOF
</select></p>
<p><input type="text" name="subject" required placeholder="在此输入帖子标题"></p>
<p><textarea required name="contents" style="width: 100% !important" onkeydown="if(event.ctrlKey && event.keyCode == 13) document.getElementById('submit').click();" placeholder="在此输入帖子内容"></textarea></p>
<p class="text-right"><input type="submit" id="submit" class="g-button g-button-red" value="发表新帖" /></p>
</form>
EOF;

$_K['footer_js'] .= '<script type="text/javascript" src="system/javascript/replyto.js"></script><script type="text/javascript" src="system/javascript/kk_pager.js"></script><script type="text/javascript">var next_page = '.($page + 1).';var prev_page = '.($page - 1).';var max_page = '.$max_page.';var page_temp = "?";disable_autopage = true;</script>';
if(!$_GET['skip']) include template('footer');